import axios from 'axios'
import Nprogress from 'nprogress'
import 'nprogress/nprogress.css'
import store from '@/store'
const Service = axios.create({
  baseURL: '/api',
  timeout: 20000
})
Service.interceptors.request.use(
  (config)=> {
    Nprogress.start()
    let userTempId = store.state.user.userTempId
    let token = store.state.user.token
    if(userTempId) {
      config.headers.userTempId = userTempId
    }
    if(token) {
      config.headers.token = token
    }
    return config
})
Service.interceptors.response.use(
  (response)=> {
    Nprogress.done()
    return response.data
},(error) => {
  alert('请求出错',"错误信息为" + error.message)
  return new Promise(() => {})
})
export default Service